package com.example.star.mapper;

import com.example.star.entity.Favorite;
import com.example.star.entity.Feedback;
import com.example.star.entity.Reply;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ReplyMapper {
    @Insert("INSERT INTO reply (adminName,userName, message,send_time) VALUES (#{adminName}, #{userName},#{message},NOW())")
    void insertReply(Reply reply);

    @Select("SELECT * FROM reply")
    List<Reply> getAllReply();

    @Select("SELECT * FROM reply WHERE userName = #{userName}")
    List<Reply> getRepliesByUserName(String userName);

    @Delete("DELETE FROM reply WHERE id = #{id}")
    void deleteReplyById(int id);

    @Select("SELECT * FROM reply LIMIT #{offset}, #{limit}")
    List<Reply> getReplyByPage(@Param("offset") int offset, @Param("limit") int limit);
    @Select("SELECT COUNT(*) FROM reply")
    int getTotalReply();

    // 根据用户名分页获取回复信息
    @Select("SELECT * FROM reply WHERE userName = #{userName} LIMIT #{offset}, #{limit}")
    List<Reply> getRepliesByUserNameAndPage(@Param("userName") String userName, @Param("offset") int offset, @Param("limit") int limit);

    // 根据用户名获取回复信息的总数
    @Select("SELECT COUNT(*) FROM reply WHERE userName = #{userName}")
    int getTotalRepliesByUserName(@Param("userName") String userName);
}